import pygame, math, sys, random
from Player import Player
from BaseBlock import Block
from BaseEnemy import BaseEnemy
from Enemies.Skeleton import Skeleton
from BaseLevel import level
from BackGrounds.BackGround1 import Background
pygame.init()

clock = pygame.time.Clock()

screenWidth = 1024
screenHeight = 768

screenSize = screenWidth, screenHeight

all = pygame.sprite.OrderedUpdates()
blocks = pygame.sprite.Group()

Player.containers = all
BaseEnemy.containers = all
Block.containers = all
Background.containers = all

"""bgList = []
for x in range(-2000,2000,100):
    for y in range(0,600,100):
        bgList += [Background([x+50, y+50], screenSize)]"""

fullscreen = 0
altFlag = True

player = Player(15, [700, 400])
#skeleton = Skeleton(15, [600,400], screenSize)

screen = pygame.display.set_mode(screenSize)

map = level("Water_Level.lvl",screenSize)


red = 0
green = 148
blue = 255

bgColor = red, green, blue

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT: sys.exit()
        elif event.type == pygame.KEYDOWN:
            if (event.key == pygame.K_UP 
                or event.key == pygame.K_w):
                    player.direction("climb up")
                    print "UP!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
            elif (event.key == pygame.K_DOWN 
                or event.key == pygame.K_s):
                    player.direction("climb down")
                    print "down!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
            elif (event.key == pygame.K_RIGHT 
                or event.key == pygame.K_d):
                    player.direction("right")
                    print "Right!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
            elif (event.key == pygame.K_LEFT 
                or event.key == pygame.K_a):
                    player.direction("left")
                    print "Left!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"  
            elif (event.key == pygame.K_SPACE):
                print "i jumped"
            elif (event.key == pygame.K_RALT or event.key == pygame.K_LALT):
                altFlag = True
            elif (event.key == pygame.K_RETURN) and altFlag:
                if fullscreen == 0:
                    fullscreen = pygame.FULLSCREEN
                else:
                    fullscreen = 0
                screen = pygame.display.set_mode((screenWidth,screenHeight),fullscreen)
                pygame.display.flip()

        elif event.type == pygame.KEYUP:
            if (event.key == pygame.K_UP 
                or event.key == pygame.K_w):
                    player.direction("stop up")
            elif (event.key == pygame.K_DOWN 
                or event.key == pygame.K_s):
                    player.direction("stop down")
            elif (event.key == pygame.K_RIGHT 
                or event.key == pygame.K_d):
                    player.direction("stop right")
            elif (event.key == pygame.K_LEFT 
                or event.key == pygame.K_a):
                    player.direction("stop left")
            elif (event.key == pygame.K_RALT or event.key == pygame.K_LALT):
                altFlag = False 
                    



    all.update(player.realx, 
               player.realy, 
               player.scrolling, player.move(), player.direction(dir))    
    

    screen.fill(bgColor)    
    dirty = all.draw(screen)
    screen.blit(player.surface, player.rect)
    pygame.display.update()
    pygame.display.flip()    
    clock.tick(30)
    #print clock.get_fps()                   